﻿using System;
using System.Diagnostics;
using System.IO;
using IGM.Framework.Constants;

namespace IGM.Framework.Commons
{
    public class Logger
    {
        public static void Write(string message = null, Exception exception = null)
        {
            var content = Environment.NewLine + DateTime.Now + " " +
                             new StackTrace().GetFrame(1).GetMethod() + Environment.NewLine;

            if (!string.IsNullOrEmpty(message))
            {
                content += message + Environment.NewLine;
            }

            if (exception != null)
            {
                content += exception.Message + Environment.NewLine;
                content += exception.StackTrace + Environment.NewLine;
            }

            File.AppendAllText(Path.Combine(Environment.CurrentDirectory, FileConstants.LogFileName), content);
        }
    }
}